ngl: Handle negative scales
authorMatthias Clasen <mclasen@redhat.com>
Thu, 15 Jul 2021 20:40:13 +0000 (16:40 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 15 Jul 2021 20:40:13 +0000 (16:40 -0400)
Scale factors can be negative, but we were not
looking out for that, triggering an assertion when
trying to create a render target with negative
width of height. Avoid that.

Fixes: #4096
gsk/ngl/gsknglrenderjob.c

index 3f36d506ab5cf74847d189481dff0ce0eb24ee93..72efcae92a8216296a9261bc5e48a72106984646 100644 (file)
@@ -3725,19 +3725,23 @@ gsk_ngl_render_job_visit_node_with_offscreen (GskNglRenderJob       *job,
   {
     int max_texture_size = job->command_queue->max_texture_size;
 
-    scaled_width = ceilf (offscreen->bounds->size.width * job->scale_x);
+    scaled_width = ceilf (offscreen->bounds->size.width * fabs (job->scale_x));
     if (scaled_width > max_texture_size)
       {
         downscale_x = (float)max_texture_size / scaled_width;
         scaled_width = max_texture_size;
       }
+    if (job->scale_x < 0)
+      downscale_x = -downscale_x;
 
-    scaled_height = ceilf (offscreen->bounds->size.height * job->scale_y);
+    scaled_height = ceilf (offscreen->bounds->size.height * fabs (job->scale_y));
     if (scaled_height > max_texture_size)
       {
         downscale_y = (float)max_texture_size / scaled_height;
         scaled_height = max_texture_size;
       }
+    if (job->scale_y < 0)
+      downscale_y = -downscale_y;
   }
 
   GskNglRenderTarget *render_target;